package com.tuosha.service.impl;

import com.tuosha.model.OrdersListEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tuosha.dao.OrdersDao;
import com.tuosha.model.OrdersEntity;
import com.tuosha.service.OrdersService;



@Service("ordersServiceImpl")
public class OrdersServiceImpl implements OrdersService {
	@Autowired
	private OrdersDao ordersDao;
	
	@Override
	public OrdersEntity queryObject(Integer id){
		return ordersDao.queryObject(id);
	}
	
	@Override
	public List<OrdersEntity> queryList(Map<String, Object> map){
		return ordersDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return ordersDao.queryTotal(map);
	}
	
	@Override
	public void save(OrdersEntity orders){
		Date date=new Date();
		orders.setCreatedAt(date);
		ordersDao.save(orders);
	}
	
	@Override
	public int update(OrdersEntity orders){
		Date date=new Date();
		orders.setUpdatedAt(date);
		return ordersDao.update(orders);
	}
	
	@Override
	public int delete(Integer id){
		return ordersDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Integer[] ids){
		return ordersDao.deleteBatch(ids);
	}

	public int delById(Integer id){
		Date date=new Date();
		OrdersEntity ties= new OrdersEntity();
		ties.setId(id);
		ties.setDeletedAt(date);
		return ordersDao.update(ties);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}

	@Override
	public List<OrdersListEntity> queryAllList(Map<String, Object> map) {
		return ordersDao.queryAllList(map);
	}
}
